using System;
using System.Linq;
using System.Collections.Generic;

using DemoApp.DataAccess;

using EntModApp.EntServices.Business;
using EntModApp.EntServices.Data;

namespace DemoApp.BusinessLayer 
{
  public partial class GroupObjectRepository : 
    IGroupObjectRepository 
  {
    public IBusinessObjectCollection<IGroup> RetrieveAll()
    {
      var query = new GroupLoadSettings();
      return Retrieve(query);
    }

    public IBusinessObjectCollection<IGroup> Retrieve(GroupLoadSettings query)
    {
      query = GroupLoadSettings.FromGroupLoadSettings(query);
      if (query.AsReadonly)
      {
        var result = CslaGroupInfoCollection.GetGroupInfoCollection(query);
        return result;
      }
      else
      {
        var result = CslaGroupEditCollection.GetGroupEditCollection(query);
        return result;
      }
    }

    public IGroup RetrieveOne(GroupLoadSettings query)
    {
      query = GroupLoadSettings.FromGroupLoadSettings(query);
      if (query.AsReadonly)
      {
        var result = CslaGroupInfoCollection.GetGroupInfoCollection(query);
        return result.FirstOrDefault<IGroup>();
      }
      else
      {
        var result = CslaGroupEditCollection.GetGroupEditCollection(query);
        return result.FirstOrDefault<IGroup>();
      }
    }

    public int Count()
    {
      return Count(null);
    }

    public int Count(GroupLoadSettings query)
    {
      query = GroupLoadSettings.FromGroupLoadSettings(query);
      return CslaGroupInfoCollection.GetCount(query);
    }

    public IGroup New()
    {
      return CslaGroupEdit.New();
    }

    public void Save(IBusinessObjectCollection<IGroup> collection)
    {
      throw new NotImplementedException();
    }

    public void Save(IGroup obj)
    {
      throw new NotImplementedException();
    }
  }
}
